import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';

import 'umplugin_platform_interface.dart';

/// An implementation of [UmpluginPlatform] that uses method channels.
class MethodChannelUmplugin extends UmpluginPlatform {
  /// The method channel used to interact with the native platform.
  @visibleForTesting
  final methodChannel = const MethodChannel('umplugin');

  @override
  Future<String?> getPlatformVersion() async {
    final version = await methodChannel.invokeMethod<String>('getPlatformVersion');
    return version;
  }

    @override
  Future<dynamic> initCommon(String androidAppkey, String iosAppkey, String channel, [String? pushSecret]) async {
    List<dynamic> params = [androidAppkey, iosAppkey ,channel, pushSecret];
    final dynamic result =  await methodChannel.invokeMethod('initCommon', params);
    return result;
  }

  @override
  void onEvent(String event, Map<String,dynamic> properties) {
    List<dynamic> args = [event,properties];
    methodChannel.invokeMethod('onEvent', args);
  }

  @override
  void onProfileSignIn (String userID) {
    List<dynamic> args = [userID];
    methodChannel.invokeMethod('onProfileSignIn', args);
  }

  @override
  void onProfileSignOff () {
    methodChannel.invokeMethod('onProfileSignOff');
  }

  @override
  void setPageCollectionModeManual() {
    methodChannel.invokeMethod('setPageCollectionModeManual');
  }

  @override
  void onPageStart(String viewName) {
    List<dynamic> args = [viewName];
    methodChannel.invokeMethod('onPageStart', args);
  }

  @override
  void onPageEnd(String viewName) {
    List<dynamic> args = [viewName];
    methodChannel.invokeMethod('onPageEnd', args);
  }

  @override
  void setPageCollectionModeAuto() {
    methodChannel.invokeMethod('setPageCollectionModeAuto');
  }

  @override
  void reportError(String error) {
    List<dynamic> args = [error];
    methodChannel.invokeMethod('reportError', args);
  }
}
